// pages/guihuan/guihuan.js
const util = require('../../utils/util')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    List:[
      {
        id:1,
        img:"/tupian/分类/1.webp",
        name:"汉服儿童女短袖连衣裙",
        leixin:"长袖连衣裙",
        time:7
      },
      {
        id:2,
        img:"/tupian/分类/1.webp",
        name:"汉服儿童女短袖连衣裙",
        leixin:"长袖连衣裙",
        time:7
      }
    ],
    yuqifeiyong:0,
    openid:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      openid:wx.getStorageSync('openid')
    })
      wx.request({
        url: 'http://localhost:80/yijie/select',
        method:"POST",
        data:{
          useropenid:this.data.openid
        },
        header:{
          'content-type': 'application/x-www-form-urlencoded'
      },
      success:res=>{
        this.setData({
          List:res.data.data
        })
        console.log(this.data.List)
        var i=0
      }
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  xujie:function(e){
    console.log(e.currentTarget.dataset.index)
    console.log(this.data.openid)
    console.log(this.data.List[e.currentTarget.dataset.index].id)

    
    

    wx.request({
      url: 'http://localhost:80/lease/update',
      method:"POST",
      data:{
        user_openid:this.data.openid,
        articlesid:this.data.List[e.currentTarget.dataset.index].id
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
    },
    success:res=>{
      this.onLoad()
      wx.navigateTo({
        url: '/pages/xiangqing/xiangqing?b='+JSON.stringify(this.data.List[e.currentTarget.dataset.index])
      })
    }
    })
  },
  guihuan:function(e){
    console.log(e.currentTarget.dataset.index)
    console.log(this.data.openid)
    console.log(this.data.List[e.currentTarget.dataset.index].id)
  this.data.List[e.currentTarget.dataset.index].overtime;
 
  var date1 = util.formatDate(new Date());
    console.log(date1);
    // var a=this.data.List[e.currentTarget.dataset.index].overtime
    
    let a = new Date(date1)
    let date2 = new Date(this.data.List[e.currentTarget.dataset.index].overtime)
    let s1 = a.getTime();
    let s2 = date2.getTime();
    console.log(s1)
    console.log(s2)
    var feiyong
    if(s1>s2){
      let t=(s1-s2);
      var d=parseInt(t / 1000 / 60 / 60 / 24)
      console.log(d);
      feiyong=parseInt(d*this.data.List[e.currentTarget.dataset.index].deposit/7)
    }
    else{
      feiyong=0
    }
    console.log(feiyong)
    
    // feiyong=feiyong*this.data.number
this.setData({
  yuqifeiyong:feiyong
})
    wx.request({
      url: 'http://localhost:80/lease/update',
      method:"POST",
      data:{
        user_openid:this.data.openid,
        articlesid:this.data.List[e.currentTarget.dataset.index].id,
        yuqifeiyong:this.data.yuqifeiyong,
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
    },
    success:res=>{
      this.onLoad()
    }
    })
  }
})